<?php
    foreach($categories as $row){
        $categories_aux[] = $row;
    }
?>
<a href="<?php echo url_for("@homepage"); ?>">Logo</a>
<input type="text" placeholder="Buscar en toda la tienda..." style="padding: 5px; margin-left: 100px;" />
<input type="submit" value="Buscar" />
<hr />
<ul style="list-style: none;">
    <?php foreach($categories as $category){ ?>
        <?php if($category->getParentId()==null){ ?>
            <li style="float: left; margin: 10px;">
                <a href="<?php echo url_for("@search_by_category?category_url=".$category->getUrl()); ?>" class="search-by-category" data-category-id="<?php echo $category->getId(); ?>">
                    <?php echo $category->getName(); ?>
                </a>
            </li>
        <?php } ?>
    <?php } ?>
</ul>
<div style="clear: both;"></div>
<hr />
<?php foreach($categories_aux as $category1){ ?>
    <?php if($category1->getParentId()==null){ ?>
        <div class="categories" id="category-<?php echo $category1->getId(); ?>" style="border: 1px solid black; padding: 10px; display: none;">
            <?php foreach($categories_aux as $category2){ ?>
                <?php if($category2->getParentId()==$category1->getId()){ ?>
                    <li>
                        <a href="<?php echo url_for("@search_by_category?category_url=".$category2->getUrl()); ?>">
                            <?php echo $category2->getName(); ?>
                        </a>
                    </li>
                    <ul>
                        <?php foreach($categories_aux as $category3){ ?>
                            <?php if($category2->getId()==$category3->getParentId()){ ?>
                            <li>
                                <a href="<?php echo url_for("@search_by_category?category_url=".$category3->getUrl()); ?>">
                                    <?php echo $category3->getName(); ?>
                                </a>
                            </li>
                            <?php } ?>
                        <?php } ?>
                    </ul>
                <?php } ?>
            <?php } ?>
        </div>
    <?php } ?>
<?php } ?>
<script type="text/javascript">
$(document).ready(function(){
    $(".search-by-category").hover(function(){
        var data_category_id = $(this).attr("data-category-id");
        $(".categories").hide();
        $("#category-"+data_category_id).show();
    });
});
</script>